package IC.lir.Instrunction;

public class JumpInstruction extends Instruction {

	private Label _lable;
	private Condition _condition;
	
	public JumpInstruction(Condition cond, Label lable)
	{
		_condition = cond;
		_lable = lable;
	}
	
	public String toString()
	{
		return String.format("%s %s", _condition.toString(), _lable.toString());
	}
	
	
	public enum Condition
	{
		None("Jump", 0),
		True("JumpTrue", 1),
		False("JumpFalse", 2),
		Greater("JumpG", 3),
		GreaterOrEqule("JumpGE", 4),
		Less("JumpL", 5),
		LessOrEqule("JumpLE", 6);
		
		private int _index;
		private String _lirString; 
		private Condition(String lirString, int index)
		{
			_index = index;
			_lirString = lirString;
		}
		
		public boolean Equals(Condition cond) { return _index == cond._index; }
		public String toString() { return new String(_lirString); }
		
		public Condition InvertSides()
		{
			switch(this)
			{
			case Greater:
				return Less;
			case GreaterOrEqule:
				return LessOrEqule;
			case Less:
				return Greater;
			case LessOrEqule:
				return GreaterOrEqule;
			default:
				return this;
			}
		}
	}
}
